package com.zishuimuyu.login_wx.controller;

import com.zishuimuyu.login_wx.entity.User;
import com.zishuimuyu.login_wx.servic.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author 紫水木鱼
 */
@Slf4j
@RestController
public class LoginController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     *
     * @param
     * @param username
     * @param password
     * @return
     */
    @PostMapping("/doLogin")
    public Map doLogin(String username, String password) {
        User user = userService.selUserByName(username);
        Map map = new HashMap();
        if (Objects.isNull(user)) {
            map.put("result", "no");
        } else {
            if (Objects.equals(user.getPassword(), password)) {
                map.put("code", 200);
                map.put("result", "登录成功");
                //模拟登录
                System.out.println("登录成功");
                log.info("登录成功");
            } else {
                System.out.println("登录失败");

                map.put("result", "no");
            }
        }

        return map;
    }

}
